package com.feeyo.location

import com.amap.api.location.AMapLocationClientOption
import com.blankj.utilcode.util.Utils
import com.feeyo.groundservice.base_util.FyLog
import com.feeyo.groundservice.base_util.SuccessCallback

/**
 *作者：QLH on 2023-05-05
 *描述：定位业务管理器,对外的唯一入口
 */
object LocationManager : ILocationManager {

    private val locationClient by lazy { LocationClient(Utils.getApp()) }//定位


    fun exit() {
        locationClient.release()
        locationClient.destroy()
    }
    override fun requestOnce() {
        locationClient.requestOnce()
    }

    override fun request(internal: Long) {
        FyLog.e("location","请求定位")
        locationClient.request(internal)
    }

    override fun setLocationListener(listener: LocationListener?) {
        locationClient.setLocationListener(listener)
    }

    override fun setOption() {
        locationClient.setOption()
    }

    override fun enableBackgroundLocation(open: Boolean,notifyId:Int) {
        locationClient.enableBackgroundLocation(open,notifyId)
    }

    override fun release() {
        locationClient.release()
    }

    override fun destroy() {
        locationClient.destroy()
    }

    override fun initLocation(listener: LocationListener?) {
        setOption()
        setLocationListener(listener)
    }

    fun setGPSModel(){
        locationClient.getOption().locationMode = AMapLocationClientOption.AMapLocationMode.Device_Sensors
        FyLog.e("LocationManager","最终采用GPS定位模式")
    }

    override fun isOpenLocationPermission(callback: SuccessCallback) = GPSUtil.isOpenLocationPermission(callback)
}